package com.own.business.question.entity.po;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.own.business.question.common.base.ReplyEnvironment;
import com.own.business.question.common.handler.ReplyEnvironmentHandler;
import com.own.business.question.entity.vo.QuestionVo;
import com.own.component.common.base.entity.po.BaseModifiedSortPo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.math.BigDecimal;

/**
 * PracticeHistory
 *
 * @author 陈学礼 （你是一段成熟的代码，要学会自己改bug）
 * @version 4.0.0
 * @date 2021/05/14 15:49:28
 * @since 4.0.0
 */
@Schema(description = "练习流水表" + ConstantBeanSuffix.PO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "practice_history", autoResultMap = true)
public class PracticeHistory extends BaseModifiedSortPo {

    @Schema(description = "用户id")
    private Long fkUserId;

    @Schema(description = "练习id")
    private Long fkPracticeId;

    @Schema(description = "题目id")
    private Long fkQuestionId;

    @Schema(description = "判定结果 0-1")
    private BigDecimal judging;

    @Schema(description = "用户答案")
    private String answer;

    @Schema(description = "题目用时（ms）")
    private Long useTime;

    @TableField(typeHandler = ReplyEnvironmentHandler.class)
    private ReplyEnvironment replyEnvironment;

    @Schema(description = "作答状态 0=未作答 1=已作答 2=保存 3=废弃")
    private Integer status;

    @Schema(description = "答案的打乱顺序")
    private String keySortOrder;

    public PracticeHistory(QuestionVo question, Practice practice, Long userId) {
        this.fkQuestionId = question.getId();
        this.fkPracticeId = practice.getId();
        this.keySortOrder = question.getKeySortOrder();
        this.fkUserId = userId;
        this.replyEnvironment = practice.getReplyEnvironment();
        this.status = practice.getStatus();
    }

}
